//////////////////////////////////////////////////////////////////////////////////
//
// ActionScript 3.0 Common Library (MIT License)
// Copyright (c) 2009 AS3CommonCode | Tony Birleffi | http://www.mosaiceye.com
// 
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////////

package org.as3commoncode.utils 
{
	import flash.display.Shape;
	import flash.display.GradientType;
	import flash.geom.Matrix;
	import flash.display.SpreadMethod;
	import flash.display.BitmapData;
	import org.as3commoncode.graphics.ShapeExtended;	

	/**
	 * This is a utility class with many useful methods for drawing shapes.
	 * @see org.as3commoncode.graphics.ShapeExtended;
	 * 
	 * @author Tony Birleffi
	 */
	public class ShapeUtil extends ShapeExtended
	{
		/**
		 * Method used to draw a solid circle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var solidCircle:Shape = ShapeUtil.drawSolidCircle(0xff0000, 50, 0, 0, 1);
         * </listing>
         *
		 * @param color		color value.
		 * @param radius	radius number.
		 * @param xPos		x position.
		 * @param yPos		y position.
		 * @param alpha		alpha value.
		 * @return Shape.
		 */
		public static function drawSolidCircle(color:Number, radius:Number = 50, xPos:Number = 0, yPos:Number = 0, alpha:Number = 1):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginFill(color, alpha);
			shape.graphics.drawCircle(xPos, yPos, radius);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a gradient circle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var gradObj:Object = ShapeUtil.createLinearGrad([0xFF0000, 0x0000FF]);
         * var gradCircle:Shape = ShapeUtil.drawGradCircle(gradObj, 50, 0, 0);
         * </listing>
         *
		 * @param gradient		object gradient.
		 * @param radius		radius number.
		 * @param xPos			x position.
		 * @param yPos			y position.
		 * @return Shape.
		 */
		public static function drawGradCircle(gradient:Object, radius:Number = 50, xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginGradientFill(gradient[ 'type' ], gradient[ 'colors' ], gradient[ 'alphas' ], 
											  gradient[ 'ratios' ], gradient[ 'matrix' ]);
											  
			shape.graphics.drawCircle(xPos, yPos, radius);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a bitmap filled circle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var bmpObj:Object = ShapeUtil.createBitmapFill(bmp);
         * var bmpCircle:Shape = ShapeUtil.drawBmpCircle(bmpObj, 50, 0, 0);
         * </listing>
         *
		 * @param bitmap	object bitmap data.
		 * @param radius	radius number.
		 * @param xPos		x position.
		 * @param yPos		y position.
		 * @return Shape.
		 */
		public static function drawBmpCircle(bitmap:Object, radius:Number = 50, xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginBitmapFill(bitmap[ 'bitmap' ], bitmap[ 'matrix' ], bitmap[ 'repeat' ], bitmap[ 'smooth' ]);
			shape.graphics.drawCircle(xPos, yPos, radius);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a solid ellipse.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var solidEllipse:Shape = ShapeUtil.drawSolidEllipse(0xff0000, 120, 150, 0, 0, 1);
         * </listing>
         *
		 * @param color		color value.
		 * @param width		width value.
		 * @param height	height value.
		 * @param xPos		x position.
		 * @param yPos		y position.
		 * @param alpha		alpha value.
		 * @return Shape.
		 */
		public static function drawSolidEllipse(color:Number, width:Number = 120, height:Number = 150, 
												 xPos:Number = 0, yPos:Number = 0, alpha:Number = 1):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginFill(color, alpha);
			shape.graphics.drawEllipse(xPos, yPos, width, height);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a gradient ellipse.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var gradObj:Object = ShapeUtil.createLinearGrad([0xFF0000, 0x0000FF]);
         * var gradEllipse:Shape = ShapeUtil.drawGradEllipse(gradObj, 120, 150, 0, 0);
         * </listing>
         *
		 * @param gradient		object gradient.
		 * @param width			width value.
		 * @param height		height value.
		 * @param xPos			x position.
		 * @param yPos			y position.
		 * @return Shape.
		 */
		public static function drawGradEllipse(gradient:Object, width:Number = 120, height:Number = 150, 
												xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginGradientFill(gradient[ 'type' ], gradient[ 'colors' ], gradient[ 'alphas' ], 
											  gradient[ 'ratios' ], gradient[ 'matrix' ]);
											  
			shape.graphics.drawEllipse(xPos, yPos, width, height);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a bitmap filled ellipse.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var bmpObj:Object = ShapeUtil.createBitmapFill(bmp);
         * var bmpEllipse:Shape = ShapeUtil.drawBmpEllipse(bmpObj, 120, 150, 0, 0);
         * </listing>
         *
		 * @param bitmap		object bitmap data.
		 * @param width			width value.
		 * @param height		height value.
		 * @param xPos			x position.
		 * @param yPos			y position.
		 * @return Shape.
		 */
		public static function drawBmpEllipse(bitmap:Object, width:Number = 120, height:Number = 150, 
											   xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginBitmapFill(bitmap[ 'bitmap' ], bitmap[ 'matrix' ], bitmap[ 'repeat' ], bitmap[ 'smooth' ]);
			shape.graphics.drawEllipse(xPos, yPos, width, height);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a solid rectangle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var solidRect:Shape = ShapeUtil.drawSolidRect(0xff0000, 120, 150, 0, 0, 1);
         * </listing>
         *
		 * @param color		color value.
		 * @param width		width value.
		 * @param height	height value.
		 * @param xPos		x position.
		 * @param yPos		y position.
		 * @param alpha		alpha value.
		 * @return Shape.
		 */
		public static function drawSolidRect(color:Number, width:Number = 120, height:Number = 150, 
											  xPos:Number = 0, yPos:Number = 0, alpha:Number = 1):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginFill(color, alpha);
			shape.graphics.drawRect(xPos, yPos, width, height);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a gradient rectangle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var gradObj:Object = ShapeUtil.createLinearGrad([0xFF0000, 0x0000FF]);
         * var gradRect:Shape = ShapeUtil.drawGradRect(gradObj, 120, 150, 0, 0);
         * </listing>
         *
		 * @param gradient		object gradient.
		 * @param width			width value.
		 * @param height		height value.
		 * @param xPos			x position.
		 * @param yPos			y position.
		 * @return Shape.
		 */
		public static function drawGradRect(gradient:Object, width:Number = 120, height:Number = 150, 
											 xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginGradientFill(gradient[ 'type' ], gradient[ 'colors' ], gradient[ 'alphas' ], 
											  gradient[ 'ratios' ], gradient[ 'matrix' ]);
											  
			shape.graphics.drawRect(xPos, yPos, width, height);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a bitmap filled rectangle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var bmpObj:Object = ShapeUtil.createBitmapFill(bmp);
         * var bmpRect:Shape = ShapeUtil.drawBmpRect(bmpObj, 120, 150, 0, 0);
         * </listing>
         *
		 * @param bitmap		object bitmap data.
		 * @param width			width value.
		 * @param height		height value.
		 * @param xPos			x position.
		 * @param yPos			y position.
		 * @return Shape.
		 */
		public static function drawBmpRect(bitmap:Object, width:Number = 120, height:Number = 150, 
											xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginBitmapFill(bitmap[ 'bitmap' ], bitmap[ 'matrix' ], bitmap[ 'repeat' ], bitmap[ 'smooth' ]);
			shape.graphics.drawEllipse(xPos, yPos, width, height);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a solid rounded rectangle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var solidRoundRect:Shape = ShapeUtil.drawSolidRoundRect(0xff0000, 120, 150, 5, 5, 0, 0, 1);
         * </listing>
         *
		 * @param color				color value.
		 * @param width				width value.
		 * @param height			height value.
		 * @param ellipseWidth		horizontal corner width values.
		 * @param ellipseHeight		vertical corner height values.
		 * @param xPos				x position.
		 * @param yPos				y position.
		 * @param alpha				alpha value.
		 * @return Shape.
		 */
		public static function drawSolidRoundRect(color:Number, width:Number = 120, height:Number = 150,
												   ellipseWidth:Number = 5, ellipseHeight:Number = 5, 
											  	   xPos:Number = 0, yPos:Number = 0, alpha:Number = 1):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginFill(color, alpha);
			shape.graphics.drawRoundRect(xPos, yPos, width, height, ellipseWidth, ellipseHeight);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a gradient rounded rectangle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var gradObj:Object = ShapeUtil.createLinearGrad([0xFF0000, 0x0000FF]);
         * var gradRoundRect:Shape = ShapeUtil.drawGradRoundRect(0xff0000, 120, 150, 5, 5, 0, 0);
         * </listing>
         * 
		 * @param gradient			object gradient.
		 * @param width				width value.
		 * @param height			height value.
		 * @param ellipseWidth		horizontal corner width values.
		 * @param ellipseHeight		vertical corner height values.
		 * @param xPos				x position.
		 * @param yPos				y position.
		 * @return Shape.
		 */
		public static function drawGradRoundRect(gradient:Object, width:Number = 120, height:Number = 150, 
												  ellipseWidth:Number = 5, ellipseHeight:Number = 5, 
												  xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginGradientFill(gradient[ 'type' ], gradient[ 'colors' ], gradient[ 'alphas' ], 
											  gradient[ 'ratios' ], gradient[ 'matrix' ]);
											  
			shape.graphics.drawRoundRect(xPos, yPos, width, height, ellipseWidth, ellipseHeight);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a bitmap filled rectangle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var bmpObj:Object = ShapeUtil.createBitmapFill(bmp);
         * var bmpRoundRect:Shape = ShapeUtil.drawBmpRoundRect(bmpObj, 120, 150, 5, 5, 0, 0);
         * </listing>
		 * 
		 * @param bitmap			object bitmap data.
		 * @param width				width value.
		 * @param height			height value.
		 * @param ellipseWidth		horizontal corner width values.
		 * @param ellipseHeight		vertical corner height values.
		 * @param xPos				x position.
		 * @param yPos				y position.
		 * @return Shape.
		 */
		public static function drawBmpRoundRect(bitmap:Object, width:Number = 120, height:Number = 150, 
												 ellipseWidth:Number = 5, ellipseHeight:Number = 5,
												 xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginBitmapFill(bitmap[ 'bitmap' ], bitmap[ 'matrix' ], bitmap[ 'repeat' ], bitmap[ 'smooth' ]);
			shape.graphics.drawRoundRect(xPos, yPos, width, height, ellipseWidth, ellipseHeight);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a solid rounded rectangle complex.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var solidRoundRectComp:Shape = ShapeUtil.drawSolidRoundRectComplex(0xffffff, 120, 150, 5, 5, 5, 5, 0, 0, 1);
         * </listing>
         * 
		 * @param color				color value.
		 * @param width				width value.
		 * @param height			height value.
		 * @param topLeftRadius		top left radius value.
		 * @param topRightRadius	top right radius value.
		 * @param xPos				x position.
		 * @param yPos				y position.
		 * @param alpha				alpha value.
		 * @return Shape.
		 */
		public static function drawSolidRoundRectComplex(color:Number, width:Number = 120, height:Number = 150,
												   		  topLeftRadius:Number = 5, topRightRadius:Number = 5, vBL:Number = 5, vBR:Number = 5,
											  	   		  xPos:Number = 0, yPos:Number = 0, alpha:Number = 1):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginFill(color, alpha);
			shape.graphics.drawRoundRectComplex(xPos, yPos, width, height, topLeftRadius, topRightRadius, vBL, vBR);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a gradient rounded rectangle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var gradObj:Object = ShapeUtil.createLinearGrad([0xFF0000, 0x0000FF]);
         * var gradRoundRectComp:Shape = ShapeUtil.drawGradRoundRectComplex(gradObj, 120, 150, 5, 5, 5, 5, 0, 0);
         * </listing>
         * 
		 * @param color				color value.
		 * @param width				width value.
		 * @param height			height value.
		 * @param topLeftRadius		top left radius value.
		 * @param topRightRadius	top right radius value.
		 * @param xPos				x position.
		 * @param yPos				y position.
		 * @param alpha				alpha value.
		 * @return Shape.
		 */
		public static function drawGradRoundRectComplex(gradient:Object, width:Number = 120, height:Number = 150, 
												  		 topLeftRadius:Number = 5, topRightRadius:Number = 5, vBL:Number = 5, 
												  		 vBR:Number = 5, xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginGradientFill(gradient[ 'type' ], gradient[ 'colors' ], gradient[ 'alphas' ], 
											  gradient[ 'ratios' ], gradient[ 'matrix' ]);
											  
			shape.graphics.drawRoundRectComplex(xPos, yPos, width, height, topLeftRadius, topRightRadius, vBL, vBR);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a bitmap filled rectangle.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var bmpObj:Object = ShapeUtil.createBitmapFill(bmp);
         * var bmpRoundRectComp:Shape = ShapeUtil.drawBmpRoundRectComplex(bmpObj, 120, 150, 5, 5, 5, 5, 0, 0);
         * </listing>
         * 
		 * @param color				color value.
		 * @param width				width value.
		 * @param height			height value.
		 * @param topLeftRadius		top left radius value.
		 * @param topRightRadius	top right radius value.
		 * @param xPos				x position.
		 * @param yPos				y position.
		 * @param alpha				alpha value.
		 * @return Shape.
		 */
		public static function drawBmpRoundRectComplex(bitmap:Object, width:Number = 120, height:Number = 150, 
												 		topLeftRadius:Number = 5, topRightRadius:Number = 5, vBL:Number = 5, vBR:Number = 5,
											  	   		xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginBitmapFill(bitmap[ 'bitmap' ], bitmap[ 'matrix' ], bitmap[ 'repeat' ], bitmap[ 'smooth' ]);
			shape.graphics.drawRoundRectComplex(xPos, yPos, width, height, topLeftRadius, topRightRadius, vBL, vBR);
			shape.graphics.endFill();
			
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a solid polygon.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var solidPoly:Shape = ShapeUtil.drawSolidPolygon(0xffffff, 5, 3, 90, 0, 0, 1);
         * </listing>
         * 
		 * @param color		color value.
		 * @param radius	radius value.
		 * @param sides		number of sides.
		 * @param angle		angle value.
		 * @param xPos		x position.
		 * @param yPos		y position.
		 * @param alpha		alpha value.
		 * @return Shape.
		 */
		public static function drawSolidPolygon(color:Number, radius:Number = 5, sides:Number = 3, angle:Number = 0, 
												 xPos:Number = 0, yPos:Number = 0, alpha:Number = 1):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginFill(color, alpha);
			drawPolygon(shape, radius, sides, angle, xPos, yPos);
			shape.graphics.endFill();
						
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a gradient polygon.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var gradObj:Object = ShapeUtil.createLinearGrad([0xFF0000, 0x0000FF]);
         * var gradPoly:Shape = ShapeUtil.drawGradPolygon(gradObj, 5, 3, 90, 0, 0);
         * </listing>
         * 
		 * @param gradient		gradient fill object.
		 * @param radius		radius value.
		 * @param sides			number of sides.
		 * @param angle			angle value.
		 * @param xPos			x position.
		 * @param yPos			y position.
		 * @param alpha			alpha value.
		 * @return Shape.
		 */
		public static function drawGradPolygon(gradient:Object, radius:Number = 5, sides:Number = 3, 
												angle:Number = 0, xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginGradientFill(gradient[ 'type' ], gradient[ 'colors' ], gradient[ 'alphas' ], 
											  gradient[ 'ratios' ], gradient[ 'matrix' ]);
											  
			drawPolygon(shape, radius, sides, angle, xPos, yPos);
			shape.graphics.endFill();
						
			// Return.
			return shape;
		}
		
		/**
		 * Method used to draw a bitmap polygon.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var bmpObj:Object = ShapeUtil.createBitmapFill(bmp);
         * var bmpRoundRectComp:Shape = ShapeUtil.drawBmpRoundRectComplex(bmpObj, 120, 150, 5, 5, 5, 5, 0, 0);
         * </listing>
         * 
		 * @param bitmap	bitmap data object.
		 * @param radius	radius value.
		 * @param sides		number of sides.
		 * @param angle		angle value.
		 * @param xPos		x position.
		 * @param yPos		y position.
		 * @param alpha		alpha value.
		 * @return Shape.
		 */
		public static function drawBmpPolygon(bitmap:Object, radius:Number = 5, sides:Number = 3, 
											   angle:Number = 0, xPos:Number = 0, yPos:Number = 0):Shape
		{
			// Define.
			var shape:Shape = new Shape();
			
			// Draw.
			shape.graphics.beginBitmapFill(bitmap[ 'bitmap' ], bitmap[ 'matrix' ], bitmap[ 'repeat' ], bitmap[ 'smooth' ]);
			drawPolygon(shape, radius, sides, angle, xPos, yPos);
			shape.graphics.endFill();
						
			// Return.
			return shape;
		}
		
		/**
		 * Method used to return a linear gradient object.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var gradObj:Object = ShapeUtil.createLinearGrad([0xFF0000, 0x0000FF]);
         * </listing>
         * 
		 * @param colors	array of color values.
		 * @param width		width of the gradient box.
		 * @param height	height of the gradient box.
		 * @param angle		angle of the gradient.
		 * @param alphas	array of alphas.
		 * @param ratios	array of ratios.
		 * @param matrix	matrix.
		 * @param spread	spread method.
		 * @return Object.
		 */
		public static function createLinearGrad(colors:Array, width:Number = 100, height:Number = 100, angle:Number = 0, 
												 alphas:Array = null, ratios:Array = null, spread:String = null):Object
		{
			// Setup the rotation.
			var m:Matrix = new Matrix();
			m.createGradientBox(width, height, MathUtil.degreesToRadians(angle), 0, 0);
			
			// Define the spread.
  			spread = (spread == null) ? SpreadMethod.PAD : spread;
  
			// Define.
  			var obj:Object =
  			{
  				type: GradientType.LINEAR,
  				colors: colors,
  				alphas: (alphas == null) ? [ 1, 1 ] : alphas,
  				ratios: (ratios == null) ? [ 0, 255 ] : ratios,
  				matrix: m,
  				spread: spread
  			};
  			
  			// Return.
			return obj;
		}
		
		/**
		 * Method used to return a radial gradient object.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var gradObj:Object = ShapeUtil.createRadialGrad([0xFF0000, 0x0000FF]);
         * </listing>
         * 
		 * @param colors	array of color values.
		 * @param angle		angle of the gradient.
		 * @param alphas	array of alphas.
		 * @param ratios	array of ratios.
		 * @param spread	spread method.
		 * @return Object.
		 */
		public static function createRadialGrad(colors:Array, angle:Number = 0, alphas:Array = null, 
												 ratios:Array = null, spread:String = null):Object
		{
			// Setup the rotation.
			var m:Matrix = new Matrix();
			m.createGradientBox(100, 100, MathUtil.degreesToRadians(angle), 0, 0);
			
			// Define the spread.
  			spread = (spread == null) ? SpreadMethod.PAD : spread;
  			
			// Define.
  			var obj:Object =
  			{
  				type: GradientType.RADIAL, 
  				colors: colors,
  				alphas: (alphas == null) ? [ 1, 1 ] : alphas,
  				ratios: (ratios == null) ? [ 0, 255 ] : ratios,
  				matrix: m,
  				spread: spread
  			};
  			
  			// Return.
			return obj;
		}
		
		/**
		 * Method used to return a bitmap fill object.
		 * 
		 * @example
		 * <listing>
         * import org.as3commoncode.utils.ShapeUtil;
         * var bmpObj:Object = ShapeUtil.createBitmapFill(bmp, 0, true, true);
         * </listing>
         * 
		 * @param bitmap	bitmap data.
		 * @param angle		angle number.
		 * @param repeat	boolean to repeat the tile or not.
		 * @param smooth	to make it smooth or not.
		 * @return Object.
		 */
		public static function createBitmapFill(bitmap:BitmapData, angle:Number = 0,
												 repeat:Boolean = true, smooth:Boolean = false):Object
		{
			// Setup the rotation.
			var m:Matrix = new Matrix();
			m.createGradientBox(100, 100, MathUtil.degreesToRadians(angle), 0, 0);
			
			// Define.
			var obj:Object = 
			{
				bitmap: bitmap,
				matrix: m,
				repeat: repeat,
				smooth: smooth
			};
			
			// Return.
			return obj;
		}
	}
}
